package com.xugongzhang.api;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

/**
 * @author X
 * @date 2022/6/29 0:32
 */
public class CompletableFutureApiDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "yue";
        });
        // System.out.println(completableFuture.getNow("yue!"));
        System.out.println(completableFuture.complete("completeValue") + "===" + completableFuture.join());
    }
}
